package cn.ubeta.b2c.api;

import cn.ubeta.b2c.utils.Constants;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by denny on 16/9/18.
 */

public class ApiHelper<T> {

    public T create() {
        // 获取泛型class
        Type genType = getClass().getGenericSuperclass();
        Type[] params = ((ParameterizedType) genType).getActualTypeArguments();
        Class<T> clazz =  (Class)params[0];

        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl(Constants.SERVER_HOST)
                .addConverterFactory(GsonConverterFactory.create())
                .build();
        return retrofit.create(clazz);
    }
}
